﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alarm
{

    public delegate void Action(object sender, Time time, Time alarttime);

    public class Time
    {
        public int hour { get; set; }
        public int minute { get; set; }
    }

    public class Alarm
    {
        public event Action Running;

        public void Run(int nowhour,int nowminute,int alarthour , int alarmminute)
        {
            Time nowtime = new Time();
            nowtime.hour = nowhour;
            nowtime.minute = nowminute;

            Time alarmtime = new Time();
            alarmtime.hour = alarthour;
            alarmtime.minute = alarmminute;

            while (true)
            {
                Running(this, nowtime, alarmtime);
                nowtime.hour = ((nowtime.minute + 1) / 60 + nowtime.hour) %24;
                nowtime.minute = (nowtime.minute + 1)%60;
            }
        }
    }

    public class SetAlarm
    {
        public Alarm alarm = new Alarm();

        public SetAlarm()
        {
            alarm.Running += new Action(StartAlarm);
            alarm.Running += Tick;
        }

        void StartAlarm(object sender,Time time, Time alarmtime)
        {
            if(time.hour == alarmtime.hour && time.minute == alarmtime.minute)
            {
                Console.WriteLine("闹钟在 {0}：{1} 响铃了", time.hour, time.minute);
            }
        }

        void Tick(object sender, Time time , Time alarmtime)
        {
            Console.WriteLine("当前时间 {0}：{1}", time.hour, time.minute);
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            SetAlarm alarm = new SetAlarm();
            alarm.alarm.Run(1,0,1,5);
        }
    }

}
